﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter8.Section2
{
    public class Example02
    {
        public Example02()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double[], double[]> ff
                = new V.Function.ToLastType<double[], double[]>(func);
            V.Surface s = new V.Surface(ff);
            s.Parameter1StartValue = 0.0;
            s.Parameter1EndValue = 1.0;
            s.Parameter2StartValue = 0.0;
            s.Parameter2EndValue = 2.0 * Math.PI;

            V.Function.ToLastType<double, double[]> gg
                = new V.Function.ToLastType<double, double[]>(gunc);
            V.Path p = new V.Path(gg);
            p.ParameterFrom = 0.0;
            p.ParameterTo = 2.0 * Math.PI;

            V.Function.ToLastType<double[], double[]> F
               = new V.Function.ToLastType<double[], double[]>(vectorField);

            V.StokesTheorem obj = new V.StokesTheorem(p, F, s);
            obj.Compute();

            result += obj.LeftHandSideBestEstimation.ToString() + "\r\n";
            result += obj.RightHandSideBestEstimation.ToString() + "\r\n";
            result += obj.RightHandSideStandardDeviation.ToString() + "\r\n";
            
            result += (3.0*Math.PI/2.0).ToString() + "\r\n";
        }
        private double[] func(double[] u)
        {
            double[] x = new double[3];
            x[0] = u[0] * Math.Cos(u[1]);
            x[1] = u[0] * Math.Sin(u[1]);
            x[2] = 1.0 - x[0] - x[1];
            return x;
        }
        private double[] gunc(double t)
        {
            double[] x = new double[3];
            x[0] = Math.Cos(t);
            x[1] = Math.Sin(t);
            x[2] = 1.0 - x[0] - x[1];
            return x;
        }

        private double[] vectorField(double[] x)
        {
            double[] f = new double[3];
            f[0] = -x[1] * x[1] * x[1];
            f[1] = x[0] * x[0] * x[0];
            f[2] = - x[2] * x[2] * x[2];
            return f;
        }
    }
}
/*
4.71238898033572
4.71244230720221
2.93813860001747E-05
4.71238898038469
*/